import csv
import os
import numpy as np

def combine_ans():

    print '123'
    ans1_path = '/home/dell/wxm/Code/JD/answer/Aver3_FS_W.csv'
    ans2_path = '/home/dell/wxm/Code/JD/answer/Aver3_UFS_fixed.csv'
    ans3_path = '/home/dell/wxm/Code/JD/answer/Aver3_FS_UnW.csv'
    combined_ans_path = '/home/dell/wxm/Code/JD/answer/Aver3.csv'

    f_ans1 = open(ans1_path)
    f_ans2 = open(ans2_path)
    f_ans3 = open(ans3_path)
    f_combined = file(combined_ans_path, 'wb')

    lines_ans1 = f_ans1.readlines()
    lines_ans2 = f_ans2.readlines()
    lines_ans3 = f_ans3.readlines()

    csvwriter = csv.writer(f_combined)

    for line in lines_ans1:
        line = line.strip('\n')
        name, label = line.split(',')
        label = label.strip('\r')
        answer = [name, str(label)]
        csvwriter.writerow(answer)
    for line in lines_ans2:
        line = line.strip('\n')
        name, label = line.split(',')
        label = label.strip('\r')
        answer = [name, str(label)]
        csvwriter.writerow(answer)
    for line in lines_ans3:
        line = line.strip('\n')
        name, label = line.split(',')
        label = label.strip('\r')
        answer = [name, str(label)]
        csvwriter.writerow(answer)
    f_ans1.close()
    f_ans2.close()
    f_ans3.close()
    f_combined.close()


def submit_all_rand():
    file_path = '/home/dell/wxm/Code/JD/log_records/submit/model_average/Two/Aver_64_96_noAug.csv'
    file_save_path = '/home/dell/wxm/Code/JD/log_records/ans_all_rand.csv'
    f = open(file_path,'r')
    f_save = file(file_save_path,'wb')
    csvwriter = csv.writer(f_save)

    lines = f.readlines()
    for line in lines:
        line = line.strip('\n')
        name, label = line.split(',')
        label = label.strip('\r')
        new_line = [name, str(label)]
        csvwriter.writerow(new_line)

    #random
    img_folder = '/media/dell/cb552bf1-c649-4cca-8aca-3c24afca817b/dell/wxm/Data/JD/Proc/test_washed_FS_W'
    for img in os.listdir(img_folder):
        new_line = [img, str(np.random.randint(0,40))]
        csvwriter.writerow(new_line)

    f_save.close()
    f.close()

def submit_all_pred():
    file_path1 = '/home/dell/wxm/Code/JD/log_records/submit/model_average/Two/Aver_64_96_noAug.csv'
    file_path2 = '/home/dell/wxm/Code/JD/answer/ans_NWD_heNor_e25_FS_W.csv'
    file_save_path = '/home/dell/wxm/Code/JD/log_records/ans_all_pred.csv'
    f1 = open(file_path1,'r')
    f2 = open(file_path2,'r')
    f_save = file(file_save_path,'wb')
    csvwriter = csv.writer(f_save)

    lines1 = f1.readlines()
    lines2 = f2.readlines()
    for line in lines1:
        line = line.strip('\n')
        name, label = line.split(',')
        label = label.strip('\r')
        new_line = [name, str(label)]
        csvwriter.writerow(new_line)
    for line in lines2:
        line = line.strip('\n')
        name, label = line.split(',')
        label = label.strip('\r')
        new_line = [name, str(label)]
        csvwriter.writerow(new_line)

    f_save.close()
    f1.close()
    f2.close()

if __name__ == '__main__':
    combine_ans()
